home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / cardpkg_1.3.lha / CardPkg / Hello_VBig.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-21  |  5.0 KB  |  168 lines

  1. /*** Hello_VBig.c ***/
  2.  
  3. /************************************************************
  4.  
  5.     TML's C Language Card Image Package  v1.1
  6.  
  7.     January, 1993
  8.     Todd M. Lewis             (919) 776-7386
  9.     2601 Piedmont Drive
  10.     Sanford, NC  27330-9437
  11.     USA
  12. ************************************************************/
  13. #include <stdlib.h>
  14. #include <exec/types.h>
  15. #include <intuition/intuition.h>
  16. #include <intuition/intuitionbase.h>
  17.  
  18. #ifdef AZTEC_C
  19.   #include <functions.h>
  20.   #define __far
  21. #endif
  22. #ifdef __SASC
  23.   #include <clib/alib_protos.h>
  24.   #include <clib/intuition_protos.h>
  25.   #include <clib/graphics_protos.h>
  26.   #include <clib/dos_protos.h>
  27.   #include <clib/exec_protos.h>
  28. #endif
  29.  
  30. #include "CardVBigImages.h"
  31. #include "Cards.h"
  32.  
  33. #define ShowCard     ShowVBigCard
  34. #define CARD_HEIGHT  CARD_VBIG_HEIGHT
  35. #define CARD_WIDTH   CARD_VBIG_WIDTH
  36.  
  37. extern UWORD       RangeRand( ULONG );
  38. extern ULONG __far RangeSeed;
  39.  
  40. struct IntuitionBase *IntuitionBase;
  41. struct GfxBase       *GfxBase;
  42.  
  43. #define INTUITION_REV 28
  44. #define GRAPHICS_REV  28
  45.  
  46. struct Window *Window;
  47. struct NewWindow newwindow =
  48.   {
  49.         20,20,   /* window XY origin relative to TopLeft of screen */
  50.         10+7*(CARD_WIDTH+3), 19+2*(CARD_HEIGHT+2), /* window width and height */
  51.         0,1,     /* detail and block pens */
  52.         CLOSEWINDOW,    /* IDCMP flags */
  53.         WINDOWDRAG  | WINDOWDEPTH |
  54.         WINDOWCLOSE | ACTIVATE    | NOCAREREFRESH,  /* other window flags */
  55.         NULL,   /* first gadget in gadget list */
  56.         NULL,   /* custom CHECKMARK imagery */
  57.         (UBYTE *)" Testing Card Images ",       /* window title */
  58.         NULL,   /* custom screen pointer */
  59.         NULL,   /* custom bitmap */
  60.         5,5,    /* minimum width and height */
  61.         0xffff,0xffff,  /* maximum width and height */
  62.         WBENCHSCREEN    /* destination screen type */
  63.   };
  64.  
  65. #define CX(i) ( Window->BorderLeft + 2 + (i) % 7 * (CARD_WIDTH +3))
  66. #define CY(i) ( Window->BorderTop  + 2 + (i) / 7 * (CARD_HEIGHT+2))
  67. #define CARDS 14 /* A "normal" suit and 1 "special" card at a time */
  68. CardID_t cards[CARDS];
  69.  
  70.  
  71. void clear_a_card( int i ) /* Remove a single card. */
  72.   {
  73.     ShowCard( Window->RPort, CARD_NONE, CX(i), CY(i) );
  74.   }
  75.  
  76. void clear_cards( void )  /* Clear all the cards. */
  77.   {
  78.     int i;
  79.     for (i=0; i<CARDS; i++)
  80.       {
  81.         clear_a_card( i );
  82.         Delay( 5L );
  83.       }
  84.   }
  85.  
  86. void show_a_card( int i )  /* Shows a single card ( cards[i] ). */
  87.   {
  88.     ShowCard( Window->RPort, cards[i], CX(i), CY(i) );
  89.   }
  90.  
  91. void show_cards( void )  /* Show all the cards. */
  92.   {
  93.     int i;
  94.     for (i=0; i<CARDS; i++)
  95.       show_a_card( i );
  96.   }
  97.  
  98. void bubble_sort_and_show( void )
  99.   {
  100.     CardID_t tmp;
  101.     int i,j;
  102.  
  103.     for (j=0 ;j<CARDS; j++)
  104.       for (i=0; i<(CARDS-1); i++)
  105.         if ( cards[i] > cards[i+1] )  /* CardID_t's can be compared. */
  106.           {
  107.             tmp = cards[i];
  108.                   cards[i] = cards[i+1];
  109.                              cards[i+1] = tmp;
  110.             show_a_card( i );
  111.             show_a_card( i+1);
  112.             WaitTOF();
  113.             WaitTOF();   /* Slow it down enough to see the swaps! */
  114.           }
  115.   }
  116.  
  117. void suit_loop( int suit, CardID_t special, char *screen_title )
  118.   {
  119.    if ( CardRange( &cards[      0], CARDS-1, sizeof(cards[0]), suit,  1 ) && /* Normal suit */
  120.         CardRange( &cards[CARDS-1],       1, sizeof(cards[0]), CardSuit(special), CardRank(special) ) ) /* Special cards */
  121.      {
  122.        show_cards();
  123.        SetWindowTitles( Window,"<--Click me!  Here's a suit of cards.",screen_title);
  124.        Wait(1L << Window->UserPort->mp_SigBit);
  125.  
  126.        Shuffle( cards, CARDS, sizeof(cards[0]) );
  127.        show_cards();
  128.        SetWindowTitles( Window,"<--Click me again! The Cards are Shuffled.",(UBYTE *)0xffffffff);
  129.        Wait(1L << Window->UserPort->mp_SigBit);
  130.  
  131.        SetWindowTitles( Window," Let's sort them with a Bubble sort.",(UBYTE *)0xffffffff);
  132.        bubble_sort_and_show();
  133.        SetWindowTitles( Window,"<--Click me, I'm done.",(UBYTE *)0xffffffff);
  134.        Wait(1L << Window->UserPort->mp_SigBit);
  135.      }
  136.   }
  137. main()
  138.   {
  139.    IntuitionBase = (struct IntuitionBase *)
  140.       OpenLibrary("intuition.library", (long)INTUITION_REV);
  141.    if(IntuitionBase == NULL)
  142.       exit(FALSE);
  143.  
  144.    GfxBase = (struct GfxBase *)
  145.       OpenLibrary("graphics.library", (long)GRAPHICS_REV);
  146.    if(GfxBase == NULL)
  147.       exit(FALSE);
  148.  
  149.    if(( Window = (struct Window *) OpenWindow(&newwindow)) == NULL)
  150.       exit(FALSE);
  151.  
  152.    /* RangeRand() uses RangeSeed.  We need to set RangeSeed to something  */
  153.    /* different each time we run.  Here's one way to do it...     */
  154.  
  155.    CurrentTime( &RangeSeed, &RangeSeed );
  156.  
  157.    suit_loop( SUIT_SPADES,   CARD_JOKER, "Testing SPADES (hearts, clubs, diamonds still to go).");
  158.    suit_loop( SUIT_HEARTS,   CARD_BLACK, "Testing HEARTS (clubs, diamonds still to go).");
  159.    suit_loop( SUIT_CLUBS,    CARD_BLANK, "Testing CLUBS (diamonds still to go).");
  160.    suit_loop( SUIT_DIAMONDS, CARD_BACK,  "Testing DIAMONDS.");
  161.    clear_cards();
  162.    CloseWindow (                   Window        );
  163.    CloseLibrary( (struct Library *)IntuitionBase );
  164.    CloseLibrary( (struct Library *)GfxBase       );
  165.  
  166.    return 0;
  167.   }
  168.